package cn.wsalix.templet.service.impl;

import java.util.Map;
import java.util.Observable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.anlaser.service.impl.CommonServiceImpl;
import cn.wsalix.templet.entity.Templet;
import cn.wsalix.templet.form.TempletForm;
import cn.wsalix.templet.repository.TempletRepository;
import cn.wsalix.templet.service.TempletService;
import cn.anlaser.utils.SearchFilter;
import cn.anlaser.utils.SearchFilter.Operator;

@Service("templetService")
public class TempletServiceImpl extends
		CommonServiceImpl<TempletForm, TempletRepository, Templet> implements
		TempletService {
	@Autowired
	private TempletRepository templetRepository;

	@Override
	public String module() {
		return "/templet/main";
	}

	@Override
	public TempletRepository getRepository() {
		return templetRepository;
	}

	@Override
	public Class<Templet> getEntityClazz() {
		return Templet.class;
	}

	@Override
	public Map<String, SearchFilter> buildByForm(TempletForm form) {
		Map<String, SearchFilter> filters = buildFilter();
		if (form.getCode() != null && !form.getCode().equals("")) {
			filters.put("code",
					new SearchFilter("code", Operator.EQ, form.getCode()));
		}

		if (form.getName() != null && !form.getName().equals("")) {
			filters.put("name",
					new SearchFilter("nama", Operator.EQ, form.getName()));
		}
		return filters;
	}

	@Override
	public void update(Observable o, Object arg) {
		// TODO Auto-generated method stub

	}

}
